import { defineStore } from 'pinia'
import homeApi from '@/api/home'

interface homeData {
  indexData: any
  recommendData: any
  channelData: any
}
export const useHomeStore = defineStore('home', {
  state(): homeData {
    return {
      indexData: {},
      recommendData: {},
      channelData: {}
    }
  },
  actions: {
    async getIndexData() {
      const res = await homeApi.reqIndexData()

      this.indexData = res.data.data
      console.log(res.data.data)
    },
    async getRecommendData() {
      const res = await homeApi.reqRecommendData()
      // console.log(res.data.data);
      this.recommendData = res.data.data.categoryHotSellModule
    },
    async getChannelData(id: number) {
      const res = await homeApi.reqChannelData(id)
      // console.log(res.data);
      this.channelData = res.data
    }
  },
  getters: {
    headerRes(): any {
      return this.recommendData.categoryList?.slice(0, 2)
    },
    footerRes(): any {
      return this.recommendData.categoryList?.slice(2)
    }
  }
})
